{extend name='table'}



{block name="content"}
<div class="layui-tab layui-tab-card">
    <ul class="layui-tab-title">
    {foreach $type_arr  as $k=>$v}
        {if isset($type) and $type eq $k}
        <li data-open="{:url('index')}?type={$k}" class="layui-this">{$v}</li>
         {else}
        <li data-open="{:url('index')}?type={$k}">{$v}</li>
        {/if}
    {/foreach}
    </ul>
    <div class="layui-tab-content">
        {include file='class_apply/index_search'}
        <table id="ClassApply" data-url="{:sysuri('index')}" data-target-search="form.form-search"></table>
    </div>
</div>
<script>

    var account_show = {$account_show};

    $(function () {
        $('#ClassApply').layTable({
            even: true, height: 'full',
            sort: {field: 'id', type: 'desc'},
            where:{type:"{$type}"},
            cols: [[
                {checkbox: true, fixed: true},
                //{field: 'platform_name', title: '{:lang("学校")}', minWidth: 100, align: 'center', hide:!account_show },
                {field: 'index_user_name', title: '{:lang("会员名称")}', minWidth: 150, align: 'center', },
                {field: 'index_user_college', title: '{:lang("学校")}', minWidth: 250, align: 'center', },
                {field: 'index_user_background', title: '{:lang("学历")}', minWidth: 100, align: 'center', },
                {field: 'class_name', title: '{:lang("申请课程")}', minWidth: 100, align: 'center' },
                {field: 'user_name', title: '{:lang("创建老师")}', minWidth: 100, align: 'center'},
                {if $type == 'all' || $type == 'apply' || $type == 'agree'}
                {field: 'apply_reason', title: '{:lang("申请理由")}', minWidth: 200, align: 'center'},
                {/if}
                {if  $type == 'refuse'}
                {field: 'check_remark', title: '{:lang("拒绝理由")}', minWidth: 200, align: 'center', templet: function (d) {
                return "<span style='color: red;'>"+ d.check_remark +"</span>";}
                 },
                {/if}
                {if $type == 'all'} {field: 'status', title: '{:lang("状态")}', align: 'center', width: 100, templet: '#StatusSwitchTpl'}, {/if}
                {field: 'create_at', title: '{:lang("申请时间")}', align: 'center', minWidth: 170, sort: true},
                {if $type == 'all' || $type == 'apply' } {toolbar: '#toolbar', title: '{:lang("操作面板")}', align: 'center', minWidth: 250, fixed: 'right'} {/if}
            ]]
        });



        // 指向元素为 `<select lay-filter="test"></select>` 的选择事件
        form.on('select(platform)', function(data){

            $.ajax({
                type : 'get',
                url  : "{:sysuri('common/ajax/getTeacherList')}",
                data : {account_id:data.value},
                success:function (res) {
                    if (res.code == 1) {
                        var html = "<option value=''>{:lang('-- 请选择 --')}</option>";

                        let data = res.data;
                        for (var i in data) {

                            html += "<option value='"+i+"'>"+data[i]+"</option>";
                        }

                        $('.teacher').html(html);

                        layui.form.render('select'); // 仅渲染 select 元素
                    }
                }
            })
        });
    });
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">

    {{-d.status == 0 ? '<b class="color-red">{:lang("申请中")}</b>' : ''}}
    {{-d.status == 1 ? '<b class="color-green">{:lang("同意")}</b>' : ''}}
    {{-d.status == 2 ? '<b class="color-danger">{:lang("拒绝")}</b>' : ''}}
</script>

<script type="text/html" id="toolbar">

    {{# if (d.status == 0) { }}
    <!--{if auth("agree")}-->
    <a class="layui-btn layui-btn-sm"   data-title="{:lang('同意')}" data-action='{:url("agree")}' data-value="id#{{d.id}}">{:lang('同意')}</a>
    <!--{/if}-->

    <!--{if auth("refuse")}-->
    <a class="layui-btn layui-btn-sm layui-btn-danger"  data-modal="{:url('refuse')}" data-value="id#{{d.id}}">{:lang('拒绝')}</a>
    <!--{/if}-->
    {{# } }}

    {{# if (d.status == 2 && d.check_remark) { }}
    <span style="color: red;">拒绝理由：</span> {{d.check_remark}}
    {{# } }}
</script>
{/block}
